package com.neu.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.neu.view.App;

/**
 * SharedPreferences工具类
 */
public class SpHelper {
    //定义文件名称
    private final static String FILE_NAME="config";

    /**
     * 给文件赋值String类型
     * @param name
     * @param value
     */
    public static void setString(String name,String value){
        SharedPreferences sp=getSp(App.context);
        SharedPreferences.Editor editor=sp.edit();
        editor.putString(name,value);
        editor.commit();

    }

    public static void setBoolean(String name,boolean flag){
        SharedPreferences sp=getSp(App.context);
        SharedPreferences.Editor editor=sp.edit();
        editor.putBoolean(name,flag);
        editor.commit();
    }
    public static boolean getBoolean(String name){
        SharedPreferences sp=getSp(App.context);
        return sp.getBoolean(name,false);
    }

    /**
     * 获得String的值
     * @param name
     * @return
     */
    public static String getString(String name){
        SharedPreferences sp=getSp(App.context);
        return sp.getString(name,"");
    }

    /**
     * 获得SharedPreferences对象的方法
     * @param context
     * @return
     */
    private static SharedPreferences getSp(Context context){
        return context.getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE);
    }
}
